#pragma once
#include"RBTree.h"
template<class K, class V>
class map
{
	struct MapKeyOfT
	{
		const K& operator()(const K& kv)
		{
			return kv.first;
		}
	};

public:
	typedef typename RBTree<K, const pair<K, V>, MapKeyOfT> Itreator itreator;
	typedef typename RBTree<K, const pair<K, V>, MapKeyOfT> ConstIterator const_itreator;

	iterator begin()
	{
		return _t.Begin();
	}

	iterator end()
	{
		return _t.End();
	}

	const_iterator begin() const
	{
		return _t.Begin();
	}

	const_iterator end()  const
	{
		return _t.End();
	}

	pair<iterator, bool> insert(const pair<K, V>& kv)
	{
		return _t.Insert(kv);
	}

	V& operator[](const K& key)
	{
		pair<iterator, bool> ret = insert({ key, V() });
		return ret.first->second;
	}

private:
	RBTree<K, const pair<K, V>, MapKeyOfT> _t;
};